package com.woohua.demo.config;

import com.woohua.demo.strategy.dealer.DemoAbstractStrategy;
import com.woohua.demo.strategy.DemoStrategyHolder;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author woo hua
 */
@Component
public class ApplicationContextHolder implements ApplicationContextAware {

    @Override
    public void setApplicationContext( ApplicationContext applicationContext) throws BeansException {

        setDemoStrategy(applicationContext);
    }

    private void setDemoStrategy(ApplicationContext applicationContext) {
        Map<String, DemoAbstractStrategy> demoStrategyMap = applicationContext.getBeansOfType(DemoAbstractStrategy.class);
        demoStrategyMap.forEach((k, v) -> DemoStrategyHolder.setEventTypeDealer(v));

    }
}